﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ВУИ
{
    public partial class Diagn : Form
    {
        public int id;
        public Form1 Main;
        List<int> sort1;
        List<int> sort2;
        public Diagn(int ID, Form1 MAIN)
        {
            InitializeComponent();
            id = ID;
            Main = MAIN;
            sort1 = new List<int>();
            sort2 = new List<int>();
            if (Main.lPatient[Main.itnPatietn(id)].Diagnoz == null) Main.lPatient[Main.itnPatietn(id)].Diagnoz = new diagnoz();
            if (Main.lPatient[Main.itnPatietn(id)].Diagnoz.etiolog == null) Main.lPatient[Main.itnPatietn(id)].Diagnoz.etiolog = new List<int>();
            if (Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ == null) Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ = new List<int>();
           
            if (Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ == null) Main.lPatient[Main.itnPatietn(id)].Diagnoz.alterEtiolog = "";
            foreach (etiologAtt e in Main.lEtiAtt)
            {
                checkedListBox1.Items.Add(e.name, Main.lPatient[Main.itnPatietn(id)].Diagnoz.etiolog.IndexOf(e.id) >= 0);
                sort1.Add(e.id);
            }
            foreach (organ e in Main.lOrgan)
            {
                checkedListBox2.Items.Add(e.name, Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ.IndexOf(e.id) >= 0);
                sort2.Add(e.id);
            }
            textBox1.Text = Main.lPatient[Main.itnPatietn(id)].Diagnoz.mkb;
            textBox2.Text = Main.lPatient[Main.itnPatietn(id)].Diagnoz.alterEtiolog;
            textBox3.Text = Main.lPatient[Main.itnPatietn(id)].Diagnoz.alterOrgan;
           
    
            
        }

        private void Diagn_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Main.lPatient[Main.itnPatietn(id)].Diagnoz.etiolog.Clear();
            foreach (object i in checkedListBox1.CheckedItems)
            {
                Main.lPatient[Main.itnPatietn(id)].Diagnoz.etiolog.Add(sort1[checkedListBox1.Items.IndexOf(i)]);
            }
            Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ.Clear();
            foreach (object i in checkedListBox2.CheckedItems)
            {
                Main.lPatient[Main.itnPatietn(id)].Diagnoz.organ.Add(sort2[checkedListBox2.Items.IndexOf(i)]);
            }
            Main.lPatient[Main.itnPatietn(id)].Diagnoz.mkb = textBox1.Text;
            Main.lPatient[Main.itnPatietn(id)].Diagnoz.alterEtiolog = textBox2.Text;
            Main.lPatient[Main.itnPatietn(id)].Diagnoz.alterOrgan = textBox3.Text;
            Main.DetiTre_AfterSelect(this, Main.DetiTreEvent);
            Close();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            DiagOt d = new DiagOt(Main, id);
            d.ShowDialog();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ShemaOtt d = new ShemaOtt(Main, id);
            d.ShowDialog();
        }
    }
}
